<template>
  <div>
      <el-card>
        <el-form class="search" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" @submit.native.prevent>
                                      <!--<el-form-item label="发布时间" prop="releaseTime">-->
            <!--<el-date-picker clearable size="small" style="width: 200px"-->
              <!--v-model="queryParams.releaseTime"-->
              <!--type="date"-->
              <!--value-format="yyyy-MM-dd"-->
              <!--placeholder="选择发布时间">-->
            <!--</el-date-picker>-->
          <!--</el-form-item>-->
          <el-form-item prop="dateRange">
            <el-date-picker
              size="small"
              v-model="queryParams.dateRange"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              style="width: 380px;"
              align="left"
              @change="handleQuery">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="质检编号" prop="qualityCode">
            <el-input
              v-model="queryParams.qualityCode"
              placeholder="请输入质检编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
                                      <el-form-item label="取样单号" prop="samplingOrder">
            <el-input
              v-model="queryParams.samplingOrder"
              placeholder="请输入取样单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button type="primary" icon="el-icon-download" size="small" @click="exportQuery">导出</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['demo:analysis:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['demo:analysis:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['demo:analysis:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="analysisList" border @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
                                              <el-table-column label="发布时间" align="center" prop="releaseTime" />
                                      <el-table-column label="质检编号" align="center" prop="qualityCode" />
                                      <el-table-column label="取样单号" align="center" prop="samplingOrder" />
                                      <el-table-column label="TFe" align="center" prop="compTfe" />
                                      <el-table-column label="FeO" align="center" prop="compFeo" />
                                      <el-table-column label="CaO" align="center" prop="compCao" />
                                      <el-table-column label="MgO" align="center" prop="compMgo" />
                                      <el-table-column label="SiO2" align="center" prop="compSio2" />
                                      <el-table-column label="AI2O3" align="center" prop="compAl2o3" />
                                      <el-table-column label="R2" align="center" prop="compR2" />
                                      <el-table-column label="P" align="center" prop="compP" />
                                      <el-table-column label="TiO2" align="center" prop="compTio2" />
                                      <el-table-column label="S" align="center" prop="compS" />
                                      <el-table-column label="MnO" align="center" prop="compMno" />
                                      <el-table-column label="Zn" align="center" prop="compZn" />
                                      <el-table-column label="Cr" align="center" prop="compCr" />
                                      <el-table-column label="是否合格" align="center" prop="qualified" />
                                                                                                                                      <el-table-column label="备注" align="center" prop="remark" />
                      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['demo:analysis:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['demo:analysis:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改成品检化验结果对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                                            <el-form-item label="发布时间" prop="releaseTime">
              <el-date-picker clearable size="small" style="width: 200px"
                v-model="form.releaseTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择发布时间">
              </el-date-picker>
            </el-form-item>
                                                <el-form-item label="质检编号" prop="qualityCode">
              <el-input v-model="form.qualityCode" placeholder="请输入质检编号" />
            </el-form-item>
                                                <el-form-item label="取样单号" prop="samplingOrder">
              <el-input v-model="form.samplingOrder" placeholder="请输入取样单号" />
            </el-form-item>
                                                <el-form-item label="TFe" prop="compTfe">
              <el-input v-model="form.compTfe" placeholder="请输入TFe" />
            </el-form-item>
                                                <el-form-item label="FeO" prop="compFeo">
              <el-input v-model="form.compFeo" placeholder="请输入FeO" />
            </el-form-item>
                                                <el-form-item label="CaO" prop="compCao">
              <el-input v-model="form.compCao" placeholder="请输入CaO" />
            </el-form-item>
                                                <el-form-item label="MgO" prop="compMgo">
              <el-input v-model="form.compMgo" placeholder="请输入MgO" />
            </el-form-item>
                                                <el-form-item label="SiO2" prop="compSio2">
              <el-input v-model="form.compSio2" placeholder="请输入SiO2" />
            </el-form-item>
                                                <el-form-item label="AI2O3" prop="compAl2o3">
              <el-input v-model="form.compAl2o3" placeholder="请输入AI2O3" />
            </el-form-item>
                                                <el-form-item label="R2" prop="compR2">
              <el-input v-model="form.compR2" placeholder="请输入R2" />
            </el-form-item>
                                                <el-form-item label="P" prop="compP">
              <el-input v-model="form.compP" placeholder="请输入P" />
            </el-form-item>
                                                <el-form-item label="TiO2" prop="compTio2">
              <el-input v-model="form.compTio2" placeholder="请输入TiO2" />
            </el-form-item>
                                                <el-form-item label="S" prop="compS">
              <el-input v-model="form.compS" placeholder="请输入S" />
            </el-form-item>
                                                <el-form-item label="MnO" prop="compMno">
              <el-input v-model="form.compMno" placeholder="请输入MnO" />
            </el-form-item>
                                                <el-form-item label="Zn" prop="compZn">
              <el-input v-model="form.compZn" placeholder="请输入Zn" />
            </el-form-item>
                                                <el-form-item label="Cr" prop="compCr">
              <el-input v-model="form.compCr" placeholder="请输入Cr" />
            </el-form-item>
                                                <el-form-item label="是否合格" prop="qualified">
              <el-input v-model="form.qualified" placeholder="请输入是否合格" />
            </el-form-item>
                                                                                                                <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
                          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-card>
  </div>
</template>

<script>
import { pageAnalysis, getAnalysis, delAnalysis, addAnalysis, updateAnalysis, exportRecord } from '@/api/app/finish/test'

export default {
  name: 'Analysis',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 成品检化验结果表格数据
      analysisList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        releaseTime: null,
        qualityCode: null,
        samplingOrder: null,
        compTfe: null,
        compFeo: null,
        compCao: null,
        compMgo: null,
        compSio2: null,
        compAl2o3: null,
        compR2: null,
        compP: null,
        compTio2: null,
        compS: null,
        compMno: null,
        compZn: null,
        compCr: null,
        qualified: null,
        dateRange: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询成品检化验结果列表 */
    getList() {
      this.loading = true
      pageAnalysis(this.formatDateRange(this.queryParams)).then(res => {
        this.analysisList = res.data.rows
        this.total = res.data.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        releaseTime: null,
        qualityCode: null,
        samplingOrder: null,
        compTfe: null,
        compFeo: null,
        compCao: null,
        compMgo: null,
        compSio2: null,
        compAl2o3: null,
        compR2: null,
        compP: null,
        compTio2: null,
        compS: null,
        compMno: null,
        compZn: null,
        compCr: null,
        qualified: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加成品检化验结果'
    },
    exportQuery() {
      if (this.dateRange) {
        this.queryParams.startDt = this.dateRange[0]
        this.queryParams.endDt = this.dateRange[1]
      } else {
        this.queryParams.startDt = null
        this.queryParams.endDt = null
      }
      exportRecord(this.queryParams).then(res => {
        this.download(res.msg)
      })
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getAnalysis(id).then(res => {
        this.form = res.data
        this.open = true
        this.title = '修改成品检化验结果'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAnalysis(this.form).then(res => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addAnalysis(this.form).then(res => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delAnalysis(ids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
